package com.xac.common.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.xac.common.data.XacConstants;

/**
 * 封装SharedPreferences的数据存入和取出
 * 
 * @author frank
 * 
 */
public class SharePreferencesUtil {

	private Context mContext = null;
	private SharedPreferences mSp = null;
	private Editor mEditor = null;

	public SharePreferencesUtil(Context context) {
		mContext = context;
		mSp = mContext.getSharedPreferences(XacConstants.SP_FILE_NAME, Context.MODE_PRIVATE);
		mEditor = mSp.edit();
	}

	public Editor putBoolean(String key, boolean value) {
		mEditor.putBoolean(key, value);
		mEditor.commit();
		return mEditor;
	}

	public Editor putFloat(String key, float value) {
		mEditor.putFloat(key, value);
		mEditor.commit();
		return mEditor;
	}

	public Editor putInt(String key, int value) {
		mEditor.putInt(key, value);
		mEditor.commit();
		return mEditor;
	}

	public Editor putLong(String key, long value) {
		mEditor.putLong(key, value);
		mEditor.commit();
		return mEditor;
	}

	public Editor putString(String key, String value) {
		mEditor.putString(key, value);
		mEditor.commit();
		return mEditor;
	}

	public boolean getBoolean(String key, boolean defValue) {
		return mSp.getBoolean(key, defValue);
	}

	public float getFloat(String key, float defValue) {
		return mSp.getFloat(key, defValue);
	}

	public int getInt(String key, int defValue) {
		return mSp.getInt(key, defValue);
	}

	public long getLong(String key, long defValue) {
		return mSp.getLong(key, defValue);
	}

	public String getString(String key, String defValue) {
		return mSp.getString(key, defValue);
	}

}
